package com.monitor.service.impl;


import com.monitor.commons.StringUtil;
import com.monitor.dao.IGroupRightsDao;
import com.monitor.modelExt.GroupRightsExt;
import com.monitor.pubInter.AbstractBaseService;
import com.monitor.pubInter.IBaseDao;
import com.monitor.pubInter.exception.SkException;
import com.monitor.searchExt.GroupRightsSearchExt;
import com.monitor.service.IAdminPermissionGroupService;
import com.monitor.service.IGroupRightsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author afeng
 * @Date 2025-03-17 10:50:14
 * @description GroupRightsService      权限组权限关联
 */
@Service(value = "groupRightsService")
@Slf4j
public class GroupRightsServiceImpl extends AbstractBaseService<GroupRightsExt, GroupRightsSearchExt, String> implements IGroupRightsService {

    @Resource(name = "groupRightsDao")
    private IGroupRightsDao groupRightsDao;

    @Resource
    private IAdminPermissionGroupService adminPermissionGroupService;

    @Override
    public IBaseDao<GroupRightsExt, GroupRightsSearchExt, String> getDao() {
        return groupRightsDao;
    }


    @Override
    public void clearByGroupId(String groupId) {
        if (StringUtil.isNullOrEmpty(groupId)) {
            return;
        }


    }

    @Override
    public List<GroupRightsExt> getListByGroupId(String groupId) {

        if (StringUtil.isNullOrEmpty(groupId)) {
            return null;
        }

        try {
            return getAllList(GroupRightsSearchExt.getInstance().setGroupIdEq(groupId));
        } catch (SkException e) {
            return null;
        }
    }

    @Override
    public List<String> getRightsIdsByStaffId(String staffId) {
        if (StringUtil.isNullOrEmpty(staffId)) {
            return null;
        }

        List<String> groupIds = adminPermissionGroupService.getGroupIdsByAdminId(staffId);
        if (StringUtil.isNullOrEmpty(groupIds)) {
            return null;
        }

        GroupRightsSearchExt search = GroupRightsSearchExt.getInstance();
        search.setGroupIds(groupIds);

        try {
            List<GroupRightsExt> groupRightsList = getAllList(search);
            if (StringUtil.isNullOrEmpty(groupRightsList)) {

                return null;
            }
            return groupRightsList.stream().map(GroupRightsExt::getRightsId).distinct().collect(Collectors.toList());


        } catch (SkException e) {
            return null;
        }
    }
}